import { getTopMv } from '../../service/api_video'
Page({
	data: {
		topMvs: []
	},
	// 封装网络请求的方法
	async getTopMvData(offset) {
		// 显示加载动画
		wx.showNavigationBarLoading()
		const res = await getTopMv(offset)
		if(res.hasMore) {
			if(offset === 0) {
				this.setData({ topMvs: res.data })
				wx.hideNavigationBarLoading()
				wx.stopPullDownRefresh()
			}else {
				this.setData({ topMvs: [ ...this.data.topMvs, ...res.data] })
				wx.hideNavigationBarLoading()
			}
		}else {
			wx.hideNavigationBarLoading()
		}
	},
	// 页面加载 onLoad
	onLoad (options) {
		this.getTopMvData(0)
	},
	// 上拉加载更多
	onReachBottom(){
		// const res = await getTopMv(this.data.topMvs.length)
		// if(res.hasMore) this.setData({ topMvs: [ ...this.data.topMvs, ...res.data] })
		this.getTopMvData(this.data.topMvs.length)
	},
	// 下拉刷新
	onPullDownRefresh() {
		this.getTopMvData(0)
		wx.stopPullDownRefresh()
	},
	// 处理视频的点击(通过data-xxx绑定值)
	handlerVideoItemClick(event) {
		const id = event.currentTarget.dataset.item.id
		// 跳转页面
		wx.navigateTo({
			url: `/packageDetail/pages/detail-video/index?id=${id}`
		})
	}
})